package main

import (
	"fmt"
	"github.com/spf13/viper"
	"grpc/api-gateway/global"
	"grpc/api-gateway/routes"
	"grpc/api-gateway/rpc"
	"os"
	"os/signal"
	"syscall"
)

func init() {
	v := viper.New()
	v.AddConfigPath("api-gateway/resource")
	v.SetConfigType("yaml")
	v.SetConfigName("config")
	if err := v.ReadInConfig(); err != nil {
		fmt.Println(err)
		os.Exit(0)
	}
	if err := v.Unmarshal(&global.Config); err != nil {
		fmt.Println(err)
		os.Exit(0)
	}
}
func main() {
	c := make(chan os.Signal, 1)
	go func() {
		signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
	}()
	err := rpc.InitClient()
	if err != nil {
		fmt.Println(err)
	}
	//conn, err := grpc.Dial("127.0.0.1:8002", grpc.WithTransportCredentials(insecure.NewCredentials()))
	//if err != nil {
	//	log.Fatalf("did not connect: %v", err)
	//}
	//defer conn.Close()
	//rpc.UserClient =  user.NewUserClient(conn)
	defer rpc.EtcdDiscovery.CliClose()
	route := routes.InitRoute()
	if err := route.Run(":8081"); err != nil {

	}
}
